<?php
require_once 'MyPdoPublic.class.php';
class TablePublicDomain extends MyPdoPublic{

	private $tableName = 'public_domain';

	/*
		### 获取域名列表 (只获取域名项,非超管使用)
		返回json字串的域名列表如：['xxx','xx',...]
	*/
	public function _getDomainList(){
		$sql = "select domain from {$this->tableName}";
		$res = $this->dql($sql,array());
		if($res){
			foreach($res as $v){
				$res_arr[] = $v['domain'];
			}
		}else{
			$res_arr = array();
		}
		return json_encode($res_arr);
	}

	//获取域名列表 (全部数据,超管使用)
	public function _getDomainListFull(){
		$sql = "select * from {$this->tableName} order by id desc";
		return $this->dql($sql,array());
	}

	//添加域名
	public function _domainAdd($domain,$info){
		$sql = "select id from {$this->tableName} where domain = ?";
		$res = $this->dql($sql,array($domain));
		if($res){
			return 'err2';	//域名已存在	
		}else{
			$sql2 = "insert into {$this->tableName} values(null,?,?)";
			$res2 = $this->dml($sql2,array($domain,$info));
			if($res2){
				return 'ok';
			}else{
				return 'err3';	//添加异常
			}
		}
	}


	//删除域名
	public function _domainDel($id){
		$sql = "delete from {$this->tableName} where id = ?";
		$res = $this->dml($sql,array($id));
		if($res){
			return 'ok';
		}else{
			return 'err2';
		}
	}

	//多选删除域名
	public function _domainDelMulti($id_str,$id_arr){
		$sql = "delete from {$this->tableName} where id in({$id_str})";
		$res = $this->dml($sql,$id_arr);
		if($res){
			return 'ok';
		}else{
			return 'err2';
		}
	}

}